// 获取验证码
$(function () {
    $("#captcha-btn").click(function (event) {
        event.preventDefault();
        var email = $("input[name='email']").val();
        if(!email){
            amanalert.alertToast('请输入正确的新邮箱');
            return;
        }
        amanajax.get({
           'url':'/email_captcha/',
           'data':{
               'email':email
           },
            'success':function (data) {
               if(data['code'] == 1){
                   amanalert.alertSuccessToast('邮件发送成功，请注意查收！');
               }else {
                   amanalert.alertInfo(data['message']);
               }
            },
            'fail':function (error) {
                amanalert.alertNetworkError();
            }
        });
    });
});

// 修改邮箱
$(function () {
    $("#submit").click(function (event) {
        event.preventDefault();
        var emailE = $("input[name='email']");
        var captchaE = $("input[name='captcha']");

        var email = emailE.val();
        var captcha = captchaE.val();

        amanajax.post({
            'url':'/resetemail/',
            'data':{
                'email':email,
                'captcha':captcha
            },
            'success':function (data) {
                if(data['code'] == 1){
                    emailE.val("");
                    captchaE.val("");
                    amanalert.alertSuccessToast('邮箱修改成功！');
                }else {
                    amanalert.alertInfo(data['message']);
                }
            },
            'fail':function (error) {
                amanalert.alertNetworkError();
            }
        });
    });
});